home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------
- | This program demonstrates the functions in RD_STK V1.1 |
- | |
- | (c) 1991 EC Systems, 2268 Glenmoor Rd S, Clearwater, Fl 34624 |
- --------------------------------------------------------------------*/
-
- #include <graphics.h>
- #include <dos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include "rd_stk.h"
-
- static int MaxX,MaxY,StartX,StartY;
- static int x1,y1;
- static int ulx, uly, lrx, lry, size;
- static *Saucer;
- static int Maxcolor,saucercolor;
- static int r = 20;
-
- main()
- {
- int stk1_x,stk1_y,stk2_x,stk2_y;
- int stk1_b1,stk1_b2,stk2_b1,stk2_b2;
- int ch,i;
- int g_driver = DETECT; /* Request auto detection. */
- int g_mode,g_error ;
-
- void DrawBorder(void);
- void copyright(void);
- void Draw_Saucer(void);
- int set_cursor(int);
-
- /*---------------------------------------------------------------------
- | Function call to RD_STK (To turn OFF Cursor) |
- ----------------------------------------------------------------------*/
- set_cursor(OFF); /* turns cursor off */
-
- window(1,1,80,25);
- clrscr();
- if ( registerbgidriver( EGAVGA_driver ) < 0)
- exit(1);
- if ( registerbgidriver( CGA_driver ) < 0)
- exit(1);
- if ( registerbgidriver( Herc_driver ) < 0)
- exit(1);
- initgraph( &g_driver, &g_mode, "" ); /* Initialize graphics */
- g_error = graphresult(); /* Read result of init */
- if( g_error != grOk ){ /* Error occured during init */
- printf(" Graphics System Error: %s\n", grapherrormsg( g_error) );
- exit( 1 );
- }
- MaxX = getmaxx(); /* Read size of screen X */
- MaxY = getmaxy(); /* Read size of screen Y */
- StartX = (.5 * MaxX);
- StartY = (.5 * MaxY);
- Maxcolor = getmaxcolor();
- saucercolor = (Maxcolor);
- DrawBorder();
- /* Plot some "stars" */
- for ( i=0 ; i<500; ++i ){
- putpixel(random(MaxX), random(MaxY), random( Maxcolor-1 )+1);
- }
- copyright();
- for(;;){
- if(kbhit()) { /* check keyboard */
- ch = getch();
- if(ch == ESC) { /* is ESC key pressed */
- closegraph();
- textattr(WHITE + (BLACK<<4));
- set_cursor(ON_L); /* sets cursor on with line */
- window(1,1,80,25);
- clrscr();
- free( Saucer );
- exit(0); /* quit program */
- }
- }
-
- /*---------------------------------------------------------------------
- | Function call to RD_STK (for buttons position) |
- -----------------------------------------------------------------------*/
- get_joybutton(&stk1_b1,&stk1_b2,&stk2_b1,&stk2_b2);
-
- if(stk1_b2){ /* jystk1 button 2 pressed */
- closegraph();
- textattr(WHITE + (BLACK<<4));
- set_cursor(ON_L); /* sets cursor on with line */
- window(1,1,80,25);
- clrscr();
- free( Saucer );
- exit(0); /* quit program */
- }
-
- if(stk1_b1){ /* jystk1 button 1 pressed */
- if(saucercolor < Maxcolor){
- StartX = (x1 + 18);
- StartY = (y1 + 15);
- saucercolor++;
- delay(10);
- }
- if(saucercolor == Maxcolor){
- saucercolor = 1;
- }
- Draw_Saucer();
- }
-
- /*----------------------------------------------------------------------
- | Function call to RD_STK (for X & Y Stick position) |
- ----------------------------------------------------------------------*/
- get_joypos(&stk1_x, &stk1_y, &stk2_x, &stk2_y );
- x1 = stk1_x * 2;
- y1 = stk1_y * 2;
- if (x1 < 5 ) /* checks x1 min */
- x1 = 5 ;
- if (x1 > MaxX-30 ) /* checks x1 max */
- x1 = MaxX-30;
- if (y1 < 40 ) /* checks y1 min */
- y1 = 40 ;
- if (y1 > MaxY-65) /* checks y1 max */
- y1 = MaxY-65;
- putimage(x1, y1, Saucer, XOR_PUT); /* draw image */
- delay(75);
- putimage(x1, y1, Saucer, XOR_PUT); /* erase image */
- }
-
- } /* end of program */
-
- /* -------------------------------------------------------
- | function call to draw border |
- --------------------------------------------------------*/
- void DrawBorder()
- {
- struct viewporttype vp;
-
- setviewport( 1, 2, MaxX, MaxY, 1 ); /* sets window size */
- setcolor( WHITE); /* Set color to white */
- setlinestyle( SOLID_LINE, 0, THICK_WIDTH );
- getviewsettings( &vp );
- rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top );
- }
-
- /* -------------------------------------------------------
- | function call to draw copyright |
- --------------------------------------------------------*/
- void copyright()
- {
- rectangle(160,10,470,35);
- setfillstyle(SOLID_FILL,CYAN);
- floodfill(300,20,WHITE);
- outtextxy(200,15,"(C)Copyright 1991 by EC Systems");
- outtextxy(180,24," RD_STK Joystick toolbox V 1.1 ");
-
- rectangle(120,310,500,335);
- setfillstyle(SOLID_FILL, CYAN);
- floodfill(300,320,WHITE);
- outtextxy(170,315,"Press Button 1 Start or change color");
- outtextxy(180,324," Press Button 2 to Quit ");
-
- }
-
- void Draw_Saucer()
- { /* Draw Saucer */
-
- setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
- setfillstyle( SOLID_FILL,saucercolor);
- fillellipse(StartX, StartY, r, (r/3)+2);
- ellipse(StartX, StartY-4, 190, 357, r, r/3);
- line(StartX+7, StartY-6, StartX+10, StartY-12);
- circle(StartX+10, StartY-12, 2);
- line(StartX-7, StartY-6, StartX-10, StartY-12);
- circle(StartX-10, StartY-12, 2);
-
- /* Read saucer image */
-
- ulx = StartX-(r+1);
- uly = StartY-14;
- lrx = StartX+(r+1);
- lry = StartY+(r/3)+3;
- size = imagesize(ulx, uly, lrx, lry);
- Saucer = malloc( size );
- getimage(ulx, uly, lrx, lry, Saucer);
- putimage(ulx, uly, Saucer, XOR_PUT);
- delay(10);
- }